//
//  signalView.m
//  Select
//
//  Created by dihuijun on 17/3/17.
//  Copyright © 2017年 Cycle. All rights reserved.
//

#import "signalView.h"
#import "SignalAndMutipTableViewCell.h"

static NSString *IDCell = @"signsssscell";

@implementation signalView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.frame = frame;
        
        //setupTableView
        [self setupTableView];
    }
    return self;
}
- (void)setupTableView
{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.frame.size.height) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    //注册
    [self.tableView registerClass:[SignalAndMutipTableViewCell class] forCellReuseIdentifier:IDCell];
    
    [self addSubview:self.tableView];
    
    
}



#pragma mark ---- <UITableViewDelegate,UITableViewDataSource>
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.datasource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    SignalAndMutipTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:IDCell];
    
    cell.titleLabel.text = self.datasource[indexPath.row];
    
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}
///点击
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (_currentIndexPath !=nil && _currentIndexPath !=indexPath) {
        SignalAndMutipTableViewCell *cell = [tableView cellForRowAtIndexPath:_currentIndexPath];
        [cell updateButtonState:NO];
    }
    
    
    SignalAndMutipTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.buttonSelect.selected = !cell.isSelected;
    self.currentIndexPath = indexPath;
    ///传值
    _block(cell.titleLabel.text,indexPath);
    
}





/** 初始化*/
+ (signalView *)initWithFrame:(CGRect)frame{
    signalView *signal = [[signalView alloc]initWithFrame:frame];
    return signal;
}

/** 刷新*/
- (void)reloadData{
    [self.tableView reloadData];
}
@end
